import { Component, OnInit, Injector, Input } from '@angular/core';
import { GatewayPavmenuTreeComponent } from '../gateway-pavmenu-tree/gateway-pavmenu-tree.component';

@Component({
  selector: 'app-gateway-pavmenu-tree-with-data',
  templateUrl: '../gateway-pavmenu-tree/gateway-pavmenu-tree.component.html',
  styleUrls: ['./gateway-pavmenu-tree-with-data.component.css']
})
export class GatewayPavmenuTreeWithDataComponent extends GatewayPavmenuTreeComponent implements OnInit {

  constructor(
    injector: Injector
  ) {
    super(injector)
  }

  ngOnInit() {
    super.ngOnInit();
  }
  @Input() set selectedIds(ids: Array<string>) {
    setTimeout(() => {
      ids = Array.from(new Set(ids))
      //console.log(this.data)
      if(!ids){
        return;
      }
      if(ids.length == 0){
        return
      }
      let selection = []
      for (let id of ids) {
        let result = this.findInTree(this.data, id , "menuId")
        if(result){
          selection.push(result)
        }
      }
      
      this.selectedFiles = selection
      this.selectedFilesChange.emit(this.selectedFiles)
      this.expandAll()
    }, 50);
  }
}
